package org.gjy.m8.stream;

import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collector;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-08-04 14:51:43
 */
public class MyCollectorImpl implements Collector<Integer, Integer, Integer> {
    @Override
    public Supplier<Integer> supplier() {
        return () -> 0;
    }

    @Override
    public BiConsumer<Integer, Integer> accumulator() {
        return (sum, element) -> sum += element;
    }

    @Override
    public BinaryOperator<Integer> combiner() {
        return (s1, s2) -> s1 + s2;
    }

    @Override
    public Function<Integer, Integer> finisher() {
        return Function.identity();
    }

    @Override
    public Set<Characteristics> characteristics() {
        return Collections.unmodifiableSet(EnumSet.of(Collector.Characteristics.IDENTITY_FINISH));
    }
}
